import pymysql

if __name__ == '__main__':
    conn = pymysql.connect(user="root", password="root", host="127.0.0.1", port=3306, database="test")
    # 获取游标对象 执行sql
    cursor = conn.cursor()
    # 定义sql语句
    sql = "insert into stu values(1,'老张',20,1991,'北京市海淀区')"
    # 执行sql
    cursor.execute(sql)
    # 提交事务
    conn.commit()
    # 释放资源
    cursor.close()
    conn.close()
